package org.dbcopy.domain;

import java.lang.*;
import java.util.StringTokenizer;

public class ApplicationParameters{
	private String fileName;
    private String driverName;
    private String zipPath;
    private String dbUrl;
    private String nameOfUser;
    private String password;
    
    public String getZipPath() {
        return zipPath;
    }

    public void setZipPath(String zipPath) {
        this.zipPath = zipPath;
    }

	public void setFileName(String name){
		this.fileName = name;
	}

	public String getFileName(){
		return fileName;
	}

	public String getDriverName(){
		return driverName;
	}

    private String extractDbName(String url){
        StringTokenizer dbName = new StringTokenizer(url, ":");
        dbName.nextToken();
        return dbName.nextToken();
    }
    
    private String extractDriverName(String dbName){
        if (dbName.equals("postgresql")){
             return "org.postgresql.Driver";
        }
        if (dbName.equals("oracle")){
             return "oracle.jdbc.driver.OracleDriver";
        }
        if (dbName.equals("mysql")){
             return "org.gjt.mm.mysql.Driver";
        }
        if (dbName.equals("microsoft")){
             return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        }
        throw new IllegalArgumentException("Unable to find db driver for database -> " + dbName);
    }

    public void setDbUrl(String dbUrl) {
        this.dbUrl = dbUrl;
        driverName = (extractDriverName(extractDbName(dbUrl)));
    }

    public String getDbUrl(){
		return dbUrl;

	}

    public void setNameOfUser(String nameOfUser) {
        this.nameOfUser = nameOfUser;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNameOfUser(){
		return nameOfUser;
	}	
	
	
	public String getPassword(){
		return password;
	}
}